﻿namespace KinonekoSoftware.CodariaDB.Documents.Index
{
    public partial class InstanceCache : IComparable<InstanceCache>
    {
        private ObservableCollection<InstanceCache> _children;

        /// <summary>
        /// <see cref="ParentID"/> 属性用于在地理设定、种族设定、国家设定中提供树形结构支持。
        /// </summary>
        public string ParentID { get; set; }
        
        /// <summary>
        /// <see cref="Depth"/> 属性用于处理树形结构的深度问题，设计支持最高16层深度，以避免过深的结构。
        /// </summary>
        public int    Depth    { get; set; }
        
        /// <summary>
        /// <see cref="Index"/> 属性用于处理树形结构的顺序问题，为本层级内索引序号。
        /// </summary>
        public int    Index    { get; set; }
        

        [BsonIgnore]
        public ObservableCollection<InstanceCache> Children
        {
            get => _children;
            set => SetValue(ref _children, value);
        }

        [BsonIgnore]
        public int MinIndex { get; set; }
        
        [BsonIgnore]
        public int MaxIndex { get; set; }
        
        public int CompareTo(InstanceCache other)
        {
            if (ReferenceEquals(this, other)) return 0;
            if (ReferenceEquals(null, other)) return 1;
            return Index.CompareTo(other.Index);
        }
    }
}